package gui.media;// Fig 21.6: gui.media.MediaPanel.java
// A JPanel the plays media from a URL

import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URL;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
public class MediaPanel extends JPanel {
    public MediaPanel(URL mediaURL) {
        setLayout(new BorderLayout()); // use a BorderLayout

        // Use lightweight components for Swing compatibility
        Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

        try {
            // create a player to play the media specified in the URL
            Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);

            // get the components for the video and the playback controls
            Component video = mediaPlayer.getVisualComponent();
//         Component controls = mediaPlayer.getControlPanelComponent();

            if (video != null)
                add(video, BorderLayout.CENTER); // add video component

//         if ( controls != null )//todo agrega controles de audio, video y play/pausa
//            add( controls, BorderLayout.SOUTH ); // add controls

//         mediaPlayer.start(); // start playing the media clip
            PanelMediaThread mediaThread = new PanelMediaThread(mediaURL);
            mediaThread.start();

        } // end try
        catch (NoPlayerException noPlayerException) {
            System.err.println("No media player found");
        } // end catch
        catch (CannotRealizeException cannotRealizeException) {
            System.err.println("Could not realize media player");
        } // end catch
        catch (IOException iOException) {
            System.err.println("Error reading from the source");
        } // end catch
    } // end gui.media.MediaPanel constructor
} // end class gui.media.MediaPanel
